package
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.net.URLStream;
	import flash.utils.ByteArray;
	import nochump.util.zip.ZipEntry;
	import nochump.util.zip.ZipFile;
	
	/**
	 * ...
	 * @author db0@qq.com
	 */
	public class testease extends Sprite
	{
		
		public function testease()
		{
			super();
			
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		
		}
		
		private function init(e:Event = null):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			readZip();
		}
		
		//解zip
		private function readZip(e:Event = null):void
		{
			var urlStream:URLStream = new URLStream();
			urlStream.addEventListener(Event.COMPLETE, completeHandler);
			urlStream.load(new URLRequest("test.zip"));
		}
		
		private function completeHandler(event:Event):void
		{
			var datastream:URLStream = URLStream(event.target);
			var kmzFile:ZipFile = new ZipFile(datastream);
			trace(kmzFile.entries.join("@").split(".jpg").length);
			//totalMaterials = kmzFile.entries.join("@").split(".jpg").length;
			trace("kmzFile", kmzFile);
			trace("kmzFile.entries", kmzFile.entries);
			trace("kmzFile.entries.length", kmzFile.entries.length);//总文件数
			trace("kmzFile.entries.join(\"@\").split(\".jpg\").length:", kmzFile.entries.join("@").split(".jpg").length);//顶目录的长度
			for (var i:int = 0; i < kmzFile.entries.length; i++)
			{
				var entry:ZipEntry = kmzFile.entries[i];
				var data:ByteArray = kmzFile.getInput(entry);
				trace(entry.name);
				if ((entry.name.indexOf(".jpg") > -1 || entry.name.indexOf(".png") > -1))
				{
					var _loader:Loader = new Loader();
					_loader.name = entry.name.split("/").reverse()[0].split(".")[0];
					_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadBitmapCompleteHandler);
					_loader.loadBytes(data);
				}
				else if (entry.name.indexOf(".txt") > -1)
				{
					//trace(data.toString());
				}
			}
			trace("-------end-------");
		}
		
		private function loadBitmapCompleteHandler(e:Event):void
		{
			var loader:Loader = Loader(e.target.loader);
			var bitmap:Bitmap = Bitmap(loader.content);
			addChild(bitmap);
		}
	}

}